#pragma once

#include <vector>
#include "llvm/Module.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/Instruction.h"
#include "llvm/Type.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/Instructions.h"
#include <algorithm>

#include "Instrumenter.h"
#include "Utils.h"

void MemoryProfilerAlarmHandler(int);

struct MemoryProfiler
{
	MemoryProfiler(LoadInst *Inst, void*);
	bool Profile(void *Addr);

	LoadInst *Inst;
	int Misses;
	int Total;

	static vector<MemoryProfiler*> all;
	static map<Function*, vector<MemoryProfiler*> > ofFunc;
	static bool Enabled;
};

struct TerminatingMemoryProfiler
{
	TerminatingMemoryProfiler(LoadInst *Inst, void*);
	void Profile(void *Addr);
	LoadInst *Inst;
	int num;
	int Misses;

	static vector<TerminatingMemoryProfiler*> profilers;
};
